package com.yanchangapp.adapter._n_manage;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yanchangapp.R;
import com.yanchangapp.model.bean.GroupLinkManBean;

import java.util.List;

/**
 * Created by apple on 2019-10-12.
 * description:关联员工的Adapter
 */
public class GroupLinkManAdapter extends BaseQuickAdapter<GroupLinkManBean, BaseViewHolder> {

    public GroupLinkManAdapter(@Nullable List<GroupLinkManBean> data) {
        super(R.layout.item_group_linkman, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GroupLinkManBean item) {
        int position = helper.getAdapterPosition();
        // 设置分组是否显示...
        TextView tvGroupName = helper.getView(R.id.tvGroupName);
        TextView tvPersonName =  helper.getView(R.id.tvPersonName);
        String currentGroupName = item.getGroup();
        String indexDes = "";
        if (position == 0){
            indexDes = currentGroupName;
        }else {
            String beforeGroupName =  mData.get(position -1).getGroup();
            if (!beforeGroupName.equals(currentGroupName)){
                indexDes = currentGroupName;
            }
        }

        if (TextUtils.isEmpty(indexDes)){
            tvGroupName.setVisibility(View.GONE);
        }else {
            tvGroupName.setText(indexDes);
            tvGroupName.setVisibility(View.VISIBLE);
        }
        // 设置姓名
        tvPersonName.setText(item.getName());

        helper.addOnClickListener(R.id.llItem);
    }
}
